#pragma once
#include "udp_message_protocol.hpp"
#include <string>
#include <iostream>

inline bool init_socket_lib() {
#if defined(_WIN32) || defined(_WIN64)
	WSADATA wsaData;
	return WSAStartup(MAKEWORD(2, 2), &wsaData) == 0;
#else
	return true;
#endif
}
inline void cleanup_socket_lib() {
#if defined(_WIN32) || defined(_WIN64)
	WSACleanup();
#endif
}

inline socket_t create_udp_socket() { return socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); }

inline sockaddr_in make_sockaddr(const std::string &ip, uint16_t port) {
	sockaddr_in addr{};
	addr.sin_family = AF_INET;
	addr.sin_port   = htons(port);
	inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
	return addr;
}
